import java.util.ArrayList;

/*
 * Another way to work with exceptions and overloading (both add() 
 * should return a boolean value) is using a RuntimeException...
 * */

class BoundedArrayList<E> extends ArrayList
{
	public final int maxLength;
	
	public BoundedArrayList(int max)
	{
		maxLength = max;
	}
	
	public void add(E o) throws BoundOutreachedException
	{
		if (this.size()+1 > maxLength)
			throw new BoundOutreachedException();
		super.add(o);
		//System.out.println("Added: "+o);
	}
	
	public static void main(String[] args)
	{
		BoundedArrayList<String> al = new BoundedArrayList(10);
		try
		{
			al.add("Bonjour1");
			al.add("Bonjour2");
			al.add("Bonjour3");
			al.add("Bonjour4");
			al.add("Bonjour5");
			al.add("Bonjour6");
			al.add("Bonjour7");
			al.add("Bonjour8");
			al.add("Bonjour9");
			al.add("BonjourA");
			al.add("Nan");
		}
		catch (BoundOutreachedException e)
		{
			System.out.println("Le dernier ne passe vraiment pas.");
		}
	}
}
